home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / music_utilities / pt013.dms / pt013.adf / Programmers / Examples / example2.c < prev    next >
C/C++ Source or Header  |  1991-08-25  |  1KB  |  55 lines

  1. /* This program loads a module, and plays it. Uses medplayer.library.
  2.    Could be used as a small replacement of MEDPlayer. */
  3.  
  4. #include <exec/types.h>
  5. #include <libraries/dos.h>
  6. #include <proto/exec.h>
  7. #include <proto/dos.h>
  8. /* These two must be included in this order. */
  9. #include "libproto.h"
  10. #include "modplayer.h"
  11.  
  12. void main(argc,argv)
  13. int argc;
  14. char *argv[];
  15. {
  16.     struct MMD0 *sng;
  17.     register struct Library *MEDPlayerBase = 0L;
  18.     if(argc < 2) {
  19.         printf("Usage: example2 <song>\n");
  20.         return;
  21.     }
  22.     MEDPlayerBase = OpenLibrary("medplayer.library",0);
  23.     if(!MEDPlayerBase) {
  24.         printf("Can't open medplayer.library!\n");
  25.         return;
  26.     }
  27.     printf("Loading...\n");
  28.     sng = LoadModule(argv[1]);
  29.     if(!sng) {
  30.         printf("Load error (DOS error #%d).\n",IoErr());
  31.         goto exit;
  32.     }
  33.     /* Now, test if it's 5 - 8 channel module */
  34.     if(sng->song->flags & FLAG_8CHANNEL)
  35.         printf("OctaMED module - can't be played!\n");
  36.     else {
  37.         register long count,midi = 0;
  38.     /* Check if it's a MIDI song. We check the MIDI channel of
  39.     each instrument. */
  40.            for(count = 0; count < 63; count++)
  41.             if(sng->song->sample[count].midich) midi = 1;
  42.         if(GetPlayer(midi)) {
  43.             printf("Resource allocation failed.\n");
  44.             goto exit;
  45.         }
  46.         PlayModule(sng);
  47.     }
  48.     printf("Press Ctrl-C to quit.\n");
  49.     Wait(SIGBREAKF_CTRL_C);
  50. exit:
  51.     FreePlayer();
  52.     UnLoadModule(sng);
  53.     CloseLibrary(MEDPlayerBase);
  54. }
  55.